package cn.xinfei.xdecision.data.core.frame.executors.collect;


import cn.xinfei.xdecision.common.model.datax.consts.VariableConst;


import cn.xinfei.xdecision.common.model.datax.consts.VariableConst;

import cn.xinfei.xdecision.common.service.rpc.RequestContextConstant;
import cn.xinfei.xdecision.data.core.frame.check.impl.BaseVarCheckService;
import cn.xinfei.xdecision.data.core.util.XyfPreConditions;
import cn.xinfei.xdecision.model.VariableApiRequest;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;

public abstract class AbstractCollectService extends BaseVarCheckService {

    protected void varCollectInputCheck(VariableApiRequest variableApiRequest) {
        XyfPreConditions.checkArgument(
                CollectionUtils.isNotEmpty(
                        Optional.of(variableApiRequest).map(VariableApiRequest::getVarCodes).orElse(null)),
                "varCodes 不能为空！"
        );

        XyfPreConditions.checkArgument(
                Optional.of(variableApiRequest).map(VariableApiRequest::getInputParams)
                        .map(JSONObject::size)
                        .orElse(0) > 0, "inputParams 不能为空！");

        XyfPreConditions.checkArgument(
                StringUtils.isNotBlank(
                        Optional.of(variableApiRequest).map(VariableApiRequest::getRequestId).orElse(null)),
                "requestId 不能为空！"
        );

    }


    protected void varCreditChannelCheck(VariableApiRequest variableApiRequest) {
        Optional<JSONObject> inputParams = Optional.of(variableApiRequest).map(VariableApiRequest::getInputParams);
        inputParams.ifPresent(
                jsonObject -> XyfPreConditions.checkArgument(
                StringUtils.isNotBlank(jsonObject.getString(VariableConst.CREDIT_CHANNEL)),
                "征信查询必传参数 credit_channel 不能为空！"));

    }

}
